"""__author__ = 余婷"""
# # import re
# from re import *
# 
# # 1.(了解)compile(正则表达式)  - 创建正则表达式对象
# re_str = r'\d{3}'
# re_obj = compile(re_str)
# 
# # fullmatch(re_str, '234')
# # re_obj.fullmatch('234')
# 
# # 2.fullmatch  - 完全匹配
# """
# fullmatch(正则表达式, 字符串)  - 让正则和字符串完全匹配;匹配失败返回None,匹配成功返回匹配对象
# 
# 对整个字符串进行检查的时候使用，比如判断账号、密码是否合法；手机号、邮箱是否合法等
# """
# result = fullmatch(r'\d{3}[a-z]{2}[A-Z]{3}', '232anAHS')
# print(result)
# 
# # 3.match  - 匹配字符串开头
# """
# match(正则表达式, 字符串)  - 让正则和字符串开头匹配;匹配失败返回None,匹配成功返回匹配对象
# """
# result = match(r'\d{3}', '3495hsjs02-3')
# print(result)
# 
# 
# # 4.search   -  字符串查找
# """
# search(正则表达式, 字符串) - 在字符串中找到第一个和正则表达式匹配的子串；没有匹配到就返回None,否则返回匹配对象
# """
# result = search(r'a(\d{3})([A-Z]{2})', 'hello-a782KH--=23hjahsf')
# print(result)
# print('==========================================================================')
# 
# # 通过匹配对象能获取到以下内容
# # a. 匹配结果
# print(result.group())    # a782KH, 获取整个正则表达式匹配到的结果
# print(result.group(1))   # 782, 获取第一个分组匹配到的结果
# print(result.group(2))   # KH, 获取第二个分组匹配到的结果
# 
# # b.匹配范围(被匹配到的内容在原字符串中的范围-(开始下标,结束下标))
# print(result.span())
# print(result.start())
# print(result.end())
# 
# # c.获取原字符串
# print(result.string)
# 
# # 5. split - 字符串切割
# """
# split(正则表达式, 字符串, 切割次数)  - 将字符串按照满足正则表达式的子串进行切割;返回的是一个列表，列表中是被切开的子串
# 
# 切割次数 - 不传参就全切
# """
# print(split(r'\d+|[A-Z]+', 'hsj8kkjs9999lkjaHlks92jj8js9lkKIsj90kjkj'))
# 
# 
# # 6.sub - 字符串替换
# """
# sub(正则表达式,新字符串,原字符串, 替换次数)  - 将原字符串中满足正则表达式的子串替换成新字符串
# 替换次数 - 不传参就全部替换
# """
# # print('shdfjaha23hj79hjh902nm3jj'.replace('a','+'))
# print(sub(r'\d+', '*', 'how hj2h aeu8js90njj8899nnnnas'))
# 
# print(sub(r'[操肏艹草曹]|[fF]uck|shit|傻[比屄逼叉缺吊屌]|煞笔', '*', '你丫是傻叉吗? 我操你大爷的. Fuck you.'))
# 
# # 7. findall - 查找所有
# """
# findall(正则表达式, 字符串)  - 在字符串中查找所有满足正则表达式的子串，以列的形式返回
# """
# print(findall(r'\d+', 'ashd88hkjahs9hjs81hs123hj78'))
# 
# print(findall(r'\d+a', 'ashd88ahkjahs9hjs81hs123ahj78'))   # ['88a', '123a']
# # 有一个分组，只取分组匹配到的内容
# print(findall(r'(\d+)a', 'ashd88ahkjahs9hjs81hs123ahj78'))  # ['88', '123']
# 
# print(findall(r'(\d+)([a-z]{2})', 'ashd88ahkjahs9hjs81hs123ahj78'))  # [('88', 'ah'), ('9', 'hj'), ('81', 'hs'), ('123', 'ah')]
# 
# 
# # 注意：使用findall的时候，如果有分组想要取整个正则匹配的结果是取不到
# print(findall(r'(\d[a-z]){3}\+', 'ahjs8a2a8j+胡士大夫9m2s0j+接收到sd8p+ss==='))  # ['8j', '0j']
# 
# # 8. finditer - 查找所有
# """
# finditer(正则表达式, 字符串) - 在字符串中查找所有满足正则表达式的子串； 返回一个迭代器，元素是每个子串对应的匹配对象
# """
# result = finditer(r'(\d[a-z]){3}', 'ahjs8a2a8j+胡士大夫9m2s0j+接收到sd8p+ss===')
# print('==============================================================================')
# print(result)
# print('==============================================================================')
# for x in result:
#     print(x)
#     print(x.group(), x.group(1))
# 
# 
# 
# def get_name():
#     with open('data.txt', encoding='utf-8') as f:
#         content = f.read()
#         print(content)
#         re_str = r'"name":"(.+?)",'
#         result = findall(re_str, content)
#         # result = re.findall(r'\d\d','ashjf89kjskdf90naskhfk899nn,nmf67jkhh56hkhjk78')
#         print(result)
# # get_name()